package data;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author David Csejtei, CodeGuide Team, http://codeguide.hu
 */
public class Office extends Thread {
    
    private final String name;
    private int portNumber;
    private int maxAmount;
    private int p;
    
    public Office(final String name) {
        this.name = name;
        setName(name);
    }
    
    @Override
    public void run() {
        System.out.println("#"+getName()+"# | "+Math.round(System.currentTimeMillis()*0.001));
    }
    
    public String getOfficeName() {
        return name;
    }
    
    public int getP() {
        return p;
    }
    
    public int getPortNumber() {
        return portNumber;
    }

    public int getMaxAmount() {
        return maxAmount;
    }
    
    public void setPortNumber(final int portNumber) {
        this.portNumber = portNumber;
    }

    public void setMaxAmount(final int maxAmount) {
        this.maxAmount = maxAmount;
    }
    
    public void setP(final int p) {
        this.p = p;
    }
    
    @Override
    public String toString() {
        return "Office{" + "name=" + name + ", portNumber=" + portNumber + ", maxAmount=" + maxAmount + ", p=" + p + '}';
    }
    
    public void createSocket() {
        /*try {
            ///
            ServerSocket serverSocket = new ServerSocket(portNumber);

            //while(true) {
                    System.out.println("server>A Server Socket is created. | Port: "+portNumber);
                    Socket socket = serverSocket.accept();

                    //Scanner socketScanner = new Scanner(socket.getInputStream());
                    System.out.println("server>Connected.");
                    PrintWriter pw = new PrintWriter(socket.getOutputStream());

                    ArrayList<String> command = new ArrayList<String>();
                    command.add("hello");
                    command.add("bello");
                    command.add("ize");
                    command.add("exit");
                    
                    while(!command.isEmpty()) {//socketScanner.hasNextLine()) {
                            String message = command.get(0);
                            command.remove(0);

                            if(message.equals("exit")) {
                                System.out.println("server>Client exit.");
                                break;
                            } else {
                                System.out.println("server>"+message + " - received");
                                
                            }
                            pw.println(message + " - received");
                            pw.flush();
                    }

                    socket.close();
            //}
        } catch(IOException ie) {
                System.out.println(ie.getMessage());
        }*/
    }
    
    /* Office functions */
    
    public void setBet() {
        
    }
    
    public void sendResult() {
        
    }
    
    public List<Event> getEvents() {
        return null;
    }
    
}
